package net.csdn.business.kanban.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import net.csdn.business.kanban.api.entity.KanbanFieldExtension;
import net.csdn.business.kanban.api.mapper.KanbanFieldExtensionMapper;
import net.csdn.business.kanban.api.service.KanbanFieldExtensionService;
import org.springframework.stereotype.Service;
import java.util.*;

/**
 * @ClassName KanbanServiceImpl
 * @Description TODO
 * @Author liuzhisheng
 * @Date 2023/9/13
 **/
@Service
@RequiredArgsConstructor
public class KanbanFieldExtensionServiceImpl extends ServiceImpl<KanbanFieldExtensionMapper, KanbanFieldExtension> implements KanbanFieldExtensionService {
    private final KanbanFieldExtensionMapper kanbanFieldExtensionMapper;

    @Override
    public boolean removeKanbanFiledExtensions(String kanbanId) {
        return kanbanFieldExtensionMapper.removeKanbanFieldExtension(kanbanId) > 0 ? true : false;
    }

    @Override
    public List<KanbanFieldExtension> fieldExtensionsByKanbanId(String kanbanId) {
        QueryWrapper<KanbanFieldExtension> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(KanbanFieldExtension::getKanbanId,kanbanId).orderByAsc(KanbanFieldExtension::getPriority);
        return kanbanFieldExtensionMapper.selectList(queryWrapper);
    }

    @Override
    public boolean removeByFieldId(Long fieldId) {
        QueryWrapper<KanbanFieldExtension> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(KanbanFieldExtension::getFieldId,fieldId);
        return kanbanFieldExtensionMapper.delete(queryWrapper) > 0 ? true : false;
    }

    @Override
    public List<KanbanFieldExtension> fieldExtensionsByFieadId(String kanbanId,Long fieadId) {
        QueryWrapper<KanbanFieldExtension> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(KanbanFieldExtension::getKanbanId,kanbanId).eq(KanbanFieldExtension::getFieldId,fieadId).orderByAsc(KanbanFieldExtension::getPriority);
        return kanbanFieldExtensionMapper.selectList(queryWrapper);
    }
}
